package com.mooral.web.action.application;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.mooral.context.Context;
import com.mooral.web.action.MooralAction;

public class LocaleAction extends MooralAction {

	@Override
	public ActionForward perform(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			Context context) throws Exception {

		DynaActionForm dform = (DynaActionForm) form;
		String lang = ((String)dform.get("lang"));
		
        if (lang != null && lang.length() > 0) { 
            Locale locale = new java.util.Locale(lang, ""); 
            HttpSession session = request.getSession(); 
            session.setAttribute(Globals.LOCALE_KEY, locale); 
        } 

		return mapping.findForward(ACTION_SUCCESS);
	}

}
